import time
from Base.Base import Base
from selenium.webdriver.common.by import By
from selenium import webdriver

class Page(Base):
    login_loc = (By.XPATH,'/html/body/div[2]/div/div[1]/div/a[1]')
    def login(self):
        self.click(self.login_loc)

    user_loc = (By.ID,'userName')
    def user(self):
        self.send_keys(self.user_loc,'18620064667')

    pwd_loc = (By.ID,'password')
    def pwd(self):
        self.send_keys(self.pwd_loc,'Yukaiwen2580')

    loginbtn_loc = (By.ID,'save')
    def loginbtn(self):
        self.click(self.loginbtn_loc)

    que_loc = (By.ID,'bindSub')
    def que(self):
        self.click(self.que_loc)

    search_loc = (By.XPATH,'//*[@id="wd"]')
    def search(self):
        self.send_keys(self.search_loc,'茅台')

    searchbtn_loc = (By.XPATH,'/html/body/div[4]/div/div[2]/div[1]/form/input[2]')
    def searchbtn(self):
        self.click(self.searchbtn_loc)

    # 需切换窗口
    sp_loc = (By.XPATH,'/html/body/div[6]/div/div[2]/div[5]/ul/li[1]/div[2]/div[1]/a/img')
    def sp(self):
        self.click(self.sp_loc)

    gwc_loc = (By.XPATH,'//*[@id="addToCartForDetail"]')
    def gwc(self):
        self.click(self.gwc_loc)

    seegw_loc = (By.XPATH,'//*[@id="u-buy-layId"]/div/div[3]/a[2]')
    def seegw(self):
        self.click(self.seegw_loc)

    # 需切换窗口
    wode_loc = (By.XPATH,'/html/body/div[2]/div/div[2]/ul/li[1]/div[1]/a')
    def wode(self):
        self.click(self.wode_loc)

    guan_loc = (By.XPATH,'//*[@id="uGuideBox"]/div/div/span')
    def guan(self):
        self.click(self.guan_loc)

    gouwuche_loc = (By.XPATH,'/html/body/div[2]/div/div[2]/ul/li[3]/a')
    def gouwuche(self):
        self.click(self.gouwuche_loc)

    gouwushan_loc = (By.ID,'delChecked')
    def gouwushan(self):
        self.click(self.gouwushan_loc)

    shanque_loc = (By.XPATH,'/html/body/div[5]/div/div[2]/div[3]/a[1]')
    def shanque(self):
        self.click(self.shanque_loc)

    def luoji_Jiuxian_login(self):
        self.open('https://www.jiuxian.com/')
        self.login()
        time.sleep(3)
        self.user()
        self.pwd()
        time.sleep(10)
        self.loginbtn()
        time.sleep(2)
        self.que()
        time.sleep(2)

    def luoji_Jiuxian_search(self):
        self.luoji_Jiuxian_login()
        time.sleep(2)
        self.search()
        self.searchbtn()
        time.sleep(5)
        self.sp()
        self.switch_to()
        time.sleep(1)
        self.gwc()
        time.sleep(3)
        self.seegw()

    def luoji_Jiuxian_wode(self):
        self.luoji_Jiuxian_login()
        time.sleep(5)
        self.wode()
        self.switch_to()
        self.guan()
        self.gouwuche()
        self.gouwushan()
        self.shanque()